/**
 * Copyright (C) 2010-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.seequencer.client;

import java.util.HashMap;

import org.seequencer.client.common.Note;
import org.seequencer.client.instruments.Instrument;

import com.google.gwt.user.client.ui.IsWidget;

/**
 * currently i am pattern based... that might change...
 * 
 * @author ra
 * 
 */
public class InstrumentLane {

	public interface View {

		void setInstrumentLane(InstrumentLane instrumentLane);
		IsWidget asWidget();

	}

	/** FIXME: should be polyphone */
	HashMap<Integer, Note> noteMap;

	Instrument instrument;

	InstrumentLane.View view;

	public InstrumentLane(InstrumentLane.View view) {
		this.view = view;
		noteMap = new HashMap<Integer, Note>();
	}

	public void addNoteToPosition(int position, int tone) {

		System.out.println("got note: " + position + " " + tone);
		Note note = new Note();
		note.tone = tone;
		noteMap.put(position, note);

	}

	public void addInstrument(Instrument instrument) {

		this.instrument = instrument;

	}

	void playIfNoteAtPosition(int position) {

		Note note = noteMap.get(position);

		if (note != null) {
			System.out.println("telling instrument to play");
			instrument.playNote(note);
		}
	}

	public IsWidget asWidget() {
		return view.asWidget();
	}

}
